/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {number[]}
 */
 var nodesBetweenCriticalPoints = function(head) {
  let fast = head.next, slow = head
  const check = (pre, cur) => {
    if(cur.val > pre.val && cur.val > cur.next.val){
      return true
    }
    if(cur.val < pre.val && cur.val < cur.next.val){
      return true
    }
    return false
  }
  let cnt = 0
  let arr = []
  while(fast.next){
    if(check(slow, fast)){
      arr.push(cnt)
    }
    slow = slow.next
    fast = fast.next
    cnt++
  }
  if(arr.length < 2) return [-1, -1]
  let min = Infinity, max = arr[arr.length-1] - arr[0]
  for(let i = 1; i<arr.length; i++){
    min = Math.min(min, arr[i] - arr[i-1])
  }
  return [min, max]
};